package com.feifan.monthhelper.ui;

import android.os.Bundle;
import android.support.v4.widget.ContentLoadingProgressBar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.feifan.monthhelper.R;
import com.feifan.monthhelper.bean.db.DayRecordBean;
import com.feifan.monthhelper.constant.Constant;
import com.feifan.monthhelper.ui.base.BaseActivity;
import com.feifan.monthhelper.wedget.view.CirclePieView2;

import java.util.ArrayList;

import butterknife.BindView;

public class HabbitStatisticsActivity extends BaseActivity {

    @BindView(R.id.rl_title)
    View rlTitle;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.cpv_habit_evaluation)
    TextView tvHabitEvaluation;
    @BindView(R.id.tv_breakfast_progress)
    TextView tvBreakfastProgress;
    @BindView(R.id.pb_breakfast_progress)
    ContentLoadingProgressBar pbBreakfastProgress;
    @BindView(R.id.tv_fruit_progress)
    TextView tvFruitProgress;
    @BindView(R.id.pb_fruit_progress)
    ContentLoadingProgressBar pbFruitProgress;
    @BindView(R.id.tv_hot_water_progress)
    TextView tvHotWaterProgress;
    @BindView(R.id.pb_hot_water_progress)
    ContentLoadingProgressBar pbHotWaterProgress;
    @BindView(R.id.tv_sports_progress)
    TextView tvSportsProgress;
    @BindView(R.id.pb_sports_progress)
    ContentLoadingProgressBar pbSportsProgress;
    @BindView(R.id.tv_defecate_progress)
    TextView tvDefecateProgress;
    @BindView(R.id.pb_defecate_progress)
    ContentLoadingProgressBar pbDefecateProgress;
    @BindView(R.id.cpv_menstrual)
    CirclePieView2 cpvHabit;

    //最近三十天的习惯记录
    private ArrayList<DayRecordBean> habitRecordBeans;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View getTitleView() {
        return rlTitle;
    }

    @Override
    protected void initData() {
        habitRecordBeans = getIntent().getParcelableArrayListExtra(Constant.ConstantName.LAST_30_HABIT);

    }

    @Override
    protected void initView() {

        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        initHabitView();
    }

    private void initHabitView() {
        int habits = habitRecordBeans.size();
        int habitPrecent;
        String habitStr;
        if (habits < 10) {
            habitPrecent = habits * 6;
            habitStr = getResources().getString(R.string.not_good);
        } else if (habits < 20) {
            habitPrecent = (habits - 10) * 2 + 60;
            habitStr = getResources().getString(R.string.good);
        } else if (habits < 30) {
            habitPrecent = (habits - 10) * 2 + 80;
            habitStr = getResources().getString(R.string.very_good);
        } else {
            habitPrecent = 100;
            habitStr = getResources().getString(R.string.very_good);
        }
        cpvHabit.setArcPercent(habitPrecent);
        tvHabitEvaluation.setText(habitStr);

        int breakFast = 0;
        int fruit = 0;
        int defecate = 0;
        int hot_water = 0;
        int sports = 0;
        for(DayRecordBean recordBean : habitRecordBeans) {
            if(recordBean.sports) {
                sports++;
            }
            if(recordBean.breakfast) {
                breakFast++;
            }
            if(recordBean.fruit) {
                fruit++;
            }
            if(recordBean.defecate) {
                defecate++;
            }
            if(recordBean.hot_water) {
                hot_water++;
            }
        }
        tvBreakfastProgress.setText(breakFast + "/30");
        tvDefecateProgress.setText(defecate + "/30");
        tvFruitProgress.setText(fruit + "/30");
        tvHotWaterProgress.setText(hot_water + "/30");
        tvSportsProgress.setText(sports + "/30");
        pbBreakfastProgress.setProgress(breakFast);
        pbDefecateProgress.setProgress(defecate);
        pbFruitProgress.setProgress(fruit);
        pbHotWaterProgress.setProgress(hot_water);
        pbSportsProgress.setProgress(sports);
    }

    @Override
    protected int setContentLayout() {
        return R.layout.activity_habbit_statistics;
    }
}
